﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OgilvyOne.UKNow.BLL;
using OgilvyOne.UKNow.Model;

public partial class SinaM : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                string token = Request.QueryString["access_token"] != null ? Request.QueryString["access_token"] : "";
                string uid = Request.QueryString["uid"];
                string url = String.Format("https://api.weibo.com/2/users/show.json?access_token={0}&uid={1}", token, uid);
                GetDocByURL gd = new GetDocByURL(url);
                string ii = gd.GetDoc();
                if (!ii.Contains("错"))
                {
                    reg(ii.Replace("\"","'"));
                }
                Response.Write(ii);
                
            }
            catch (Exception ex )
            {
                Response.Write(ex.Message);
                
            }

            
           // Response.Write("/home.html");
            
           
        }
    }
    private void reg(string str)
    {
        AccountController acl = new AccountController(Convert.ToInt32(Request.Form["langid"]));
        string uid = str.Replace("{", "").Replace("}", "").Trim().Split(',')[0].Split(':')[1];
        MemberMappBLL mmbll = new MemberMappBLL();
        if (!mmbll.isExit(uid))
        {
            string name = str.Replace("{", "").Replace("}", "").Trim().Split(',')[3].Split(':')[1];
            MemberBLL mbll = new MemberBLL(Convert.ToInt32(Request.Form["langid"]));
            MemberModel mm = new MemberModel();
            mm.Name= name;
            mm.InsertTime = DateTime.Now;
            mm.LastLoginTime = DateTime.Now;
            int? mebid = (mbll.Save(mm).ReturnObject as MemberModel).ID;
            MemberMappMod mmm = new MemberMappMod();
            mmm.Exid = uid;
            mmm.UKid = Convert.ToInt32(mebid);
            mmm.Mtype = 2;
            mmbll.add(mmm);

            acl.ProcessLogin(mmm.UKid);


        }
        else
        {
            acl.ProcessLogin(Convert.ToInt32(mmbll.getUkid(uid)));
        }
    }

    
      
    
}